<template>
  <div style="margin: 20px">
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="关键字">
        <el-input v-model="key" placeholder="姓名/手机/身份证"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="list">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="clear">清除</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="borrowers" stripe style="width: 100%">
      <el-table-column type="index" label="序号"></el-table-column>
      <el-table-column prop="name" label="姓名" width="100"></el-table-column>
      <el-table-column
        prop="mobile"
        label="手机号码"
        width="150"
      ></el-table-column>
      <el-table-column
        prop="idCard"
        label="身份证号"
        width="180"
      ></el-table-column>
      <el-table-column prop="sex" label="性别">
        <template slot-scope="scope">
          <i>{{ scope.row.sex === 0 ? '女' : '男' }}</i>
        </template>
      </el-table-column>
      <el-table-column prop="age" label="年龄"></el-table-column>
      <el-table-column prop="marry" label="是否结婚">
        <template slot-scope="scope">
          <i>{{ scope.row.marry ? '是' : '否' }}</i>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 0">未认证</el-tag>
          <el-tag v-else-if="scope.row.status === 1">认证中</el-tag>
          <el-tag v-else-if="scope.row.status === 2">认证通过</el-tag>
          <el-tag v-else-if="scope.row.status === -1">认证失败</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="申请时间"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="warning"
            @click="handleEdit(scope.$index, scope.row)"
          >
            审批
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="text-align: center">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-sizes="[1, 3, 5, 7]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import borrowerApi from '@/api/borrower'
export default {
  data() {
    return {
      borrowers: [],
      pageNum: 1,
      pageSize: 3,
      total: 0,
      key: '',
    }
  },
  created() {
    this.list()
  },
  methods: {
    //审批按钮单击事件函数
    handleEdit(index, row) {
      // 路径参数： 需要在定义的路由中配置 row.id
      // 请求参数： 路由不需要额外的定义  参数在访问的url地址后以请求参数方式携带 url?id=xxx
      this.$router.push(`/borrower/edit/${row.id}`)
    },
    clear() {
      this.key = ''
      this.pageNum = 1
      this.list()
    },
    handleSizeChange(size) {
      this.pageSize = size
      this.list()
    },
    handleCurrentChange(num) {
      this.pageNum = num
      this.list()
    },
    list() {
      borrowerApi.list(this.pageNum, this.pageSize, this.key).then((r) => {
        this.total = r.data.page.total
        this.borrowers = r.data.page.records
      })
    },
  },
}
</script>
